import DefaultLayout from '@/layouts/DefaultLayout.vue'
import AuthLayout from '@/layouts/AuthLayout.vue'

// 懒加载组件
const Login = () => import('@/views/auth/Login.vue')
const Register = () => import('@/views/auth/Register.vue')
const Dashboard = () => import('@/views/dashboard/Index.vue')
const UserList = () => import('@/views/user/List.vue')
const UserDetail = () => import('@/views/user/Detail.vue')
const RoleList = () => import('@/views/role/List.vue')
const Permission = () => import('@/views/role/Permission.vue')
const OrderList = () => import('@/views/order/List.vue')
const RechargeList = () => import('@/views/recharge/List.vue')
const MemberList = () => import('@/views/member/List.vue')
const MemberLevel = () => import('@/views/member/Level.vue')
const HexagramModel = () => import('@/views/model/Hexagram.vue')
const AlgorithmModel = () => import('@/views/model/Algorithm.vue')
const SystemConfig = () => import('@/views/config/System.vue')
const UserStats = () => import('@/views/stats/User.vue')
const BusinessStats = () => import('@/views/stats/Business.vue')
const DivinationStats = () => import('@/views/stats/Divination.vue')
const NotFound = () => import('@/views/error/404.vue')

const routes = [
  {
    path: '/',
    redirect: '/dashboard',
    component: DefaultLayout,
    meta: { requiresAuth: true },
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: Dashboard,
        meta: { title: '仪表板', requiresAuth: true }
      },
      {
        path: '/user',
        name: 'User',
        meta: { title: '用户管理', requiresAuth: true },
        children: [
          {
            path: '/user/list',
            name: 'UserList',
            component: UserList,
            meta: { title: '用户列表', requiresAuth: true }
          },
          {
            path: '/user/detail/:id',
            name: 'UserDetail',
            component: UserDetail,
            meta: { title: '用户详情', requiresAuth: true }
          }
        ]
      },
      {
        path: '/role',
        name: 'Role',
        meta: { title: '角色权限', requiresAuth: true },
        children: [
          {
            path: '/role/list',
            name: 'RoleList',
            component: RoleList,
            meta: { title: '角色列表', requiresAuth: true }
          },
          {
            path: '/role/permission',
            name: 'Permission',
            component: Permission,
            meta: { title: '权限分配', requiresAuth: true }
          }
        ]
      },
      {
        path: '/order',
        name: 'Order',
        meta: { title: '订单管理', requiresAuth: true },
        children: [
          {
            path: '/order/list',
            name: 'OrderList',
            component: OrderList,
            meta: { title: '订单列表', requiresAuth: true }
          }
        ]
      },
      {
        path: '/recharge',
        name: 'Recharge',
        meta: { title: '充值管理', requiresAuth: true },
        children: [
          {
            path: '/recharge/list',
            name: 'RechargeList',
            component: RechargeList,
            meta: { title: '充值列表', requiresAuth: true }
          }
        ]
      },
      {
        path: '/member',
        name: 'Member',
        meta: { title: '会员管理', requiresAuth: true },
        children: [
          {
            path: '/member/list',
            name: 'MemberList',
            component: MemberList,
            meta: { title: '会员列表', requiresAuth: true }
          },
          {
            path: '/member/level',
            name: 'MemberLevel',
            component: MemberLevel,
            meta: { title: '会员等级', requiresAuth: true }
          }
        ]
      },
      {
        path: '/model',
        name: 'Model',
        meta: { title: '模型管理', requiresAuth: true },
        children: [
          {
            path: '/model/hexagram',
            name: 'HexagramModel',
            component: HexagramModel,
            meta: { title: '卦象管理', requiresAuth: true }
          },
          {
            path: '/model/algorithm',
            name: 'AlgorithmModel',
            component: AlgorithmModel,
            meta: { title: '算法管理', requiresAuth: true }
          }
        ]
      },
      {
        path: '/config',
        name: 'Config',
        meta: { title: '系统配置', requiresAuth: true },
        children: [
          {
            path: '/config/system',
            name: 'SystemConfig',
            component: SystemConfig,
            meta: { title: '系统设置', requiresAuth: true }
          }
        ]
      },
      {
        path: '/stats',
        name: 'Stats',
        meta: { title: '统计分析', requiresAuth: true },
        children: [
          {
            path: '/stats/user',
            name: 'UserStats',
            component: UserStats,
            meta: { title: '用户统计', requiresAuth: true }
          },
          {
            path: '/stats/business',
            name: 'BusinessStats',
            component: BusinessStats,
            meta: { title: '业务统计', requiresAuth: true }
          },
          {
            path: '/stats/divination',
            name: 'DivinationStats',
            component: DivinationStats,
            meta: { title: '占卜统计', requiresAuth: true }
          }
        ]
      }
    ]
  },
  {
    path: '/auth',
    component: AuthLayout,
    children: [
      {
        path: '/auth/login',
        name: 'Login',
        component: Login,
        meta: { title: '登录', requiresAuth: false }
      },
      {
        path: '/auth/register',
        name: 'Register',
        component: Register,
        meta: { title: '注册', requiresAuth: false }
      }
    ]
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: NotFound,
    meta: { title: '页面未找到', requiresAuth: false }
  }
]

export default routes